var a = localStorage.getItem("userNum");

/*
  渲染表单
*/
var vm = new Vue({
    el: '#app',

    data() {
        sex: ''
        new_passwd:""
        old_passwd:""
        return {
            name: null,
            sexNum: null,
            inYear: null,
            majorName: null,
            phoneNum: null,
            className: null,
            nationName: null,
            nativeName: null,
            idcardName: null,
            politicName: null,
            idNum: null,
            idname: null,
            image:null,
        }
    },
    mounted() {
        axios
            .get('http://39.108.233.68:8002/student/selOne', {
                params: {
                    id: a
                }
            })
            .then(response => (
                this.name = response.data.data.name,
                this.idname = response.data.data.id,
                this.sexNum = response.data.data.sex,
                this.inYear = response.data.data.inYear,
                this.majorName = response.data.data.majorName,
                this.phoneNum = response.data.data.phoneNum,
                this.className = response.data.data.className,
                this.idcardName = response.data.data.idcardName,
                this.nativeName = response.data.data.nativeName,
                this.nationName = response.data.data.nationName,
                this.politicName = response.data.data.politicName,
                this.idNum = response.data.data.idNum,
                this.image = response.data.data.image
                
            ))
            .catch(function (error) { // 请求失败处理
                console.log(error);
            });

    },
    computed: {
        sex: function () {
            if (this.sexNum == 0) {
                return "男";
            } else {
                return "女";
            }
        }

    },
    methods: {
        //获取图片地址
        getImgUrl(image){
            return require("https://www.luckyone.club/software/lesson/"+image);
        },
        edit() {
            $.ajax({
                type: 'put',
                url: 'http://39.108.233.68:8002/student/updOne',
                data: {
                    id: a,
                    phoneNum: document.getElementById("phoneNum").value,
                },
                success: function (data) {
                    //console.log(data)

                    window.location.reload();
                    alert("修改成功！");
                }
            });
        },
        change() {
            var id = a
            var new_passwd = this.new_passwd
            var old_passwd = this.old_passwd
            $.ajax({
                type: "post",
                url: 'http://39.108.233.68:8002/singleLogin',//先看密码对不对
                data: { userNum: a, password: old_passwd },
                success: function (data) {
                    if (data.msg == "成功") {
                        $.ajax({
                            type: "post",
                            url: 'http://39.108.233.68:8002/updUserPWD',
                            data: { password: new_passwd, type: 2, userNum: id },
                            success: function (data) {
                                if (data.msg == "操作成功") {
                                    alert("修改成功");
                                }
                            },
                            error: function () {
                                alert("error");
                            }
                        })
                    }
                },
                error: function () {
                    alert("密码错误");
                }
            })
        }
    }


});